import React, { Component } from 'react'

class InputName extends Component{
  render(){
    return <input type="text" value={this.props.value} onChange={this.props.onChange}/>
  }
}

//为所要改造的组件的props上赋state和方法
function withOnChange(WrappedComponent) {
  return class extends Component {
    state = {
      value: '(*^_^*)'
    }
    handleChange = (e)=> {
      this.setState({
        value: e.target.value
      })
    }
    render() {
      return (
        <WrappedComponent
          value={this.state.value}
          onChange={this.handleChange}></WrappedComponent>
      )
    }
  }
}
let WrappedInputName = withOnChange(InputName)
export default class App extends Component {
  render() {
    return (
      <div>
        <WrappedInputName></WrappedInputName>
      </div>
    )
  }
}
